#!/usr/bin/env python3
import os
import sys

emoji_dir = "/home/rainsickness/xiaoshan_opus_and_websocket/xiaoshan-develop/src/application/xiaoshan/xiaozhi-fonts/src/emoji"

for filename in os.listdir(emoji_dir):
    if filename.startswith("emoji_") and filename.endswith(".c"):
        file_path = os.path.join(emoji_dir, filename)
        
        # 读取文件内容
        with open(file_path, 'r') as f:
            lines = f.readlines()
        
        # 创建备份
        with open(file_path + '.bak', 'w') as f:
            f.writelines(lines)
        
        # 查找并替换头文件包含部分
        new_lines = []
        skip_lines = 0
        for i, line in enumerate(lines):
            if skip_lines > 0:
                skip_lines -= 1
                continue
                
            if i == 0 and line.strip() == '':  # 跳过第一行的空行
                continue
                
            # 检查是否是条件包含块的开始
            if '#if defined(LV_LVGL_H_INCLUDE_SIMPLE)' in line:
                new_lines.append('#include "lvgl.h"\n')
                # 跳过剩余的条件包含块
                skip_lines = 7  # 跳过接下来的7行
            else:
                new_lines.append(line)
        
        # 写回修改后的文件
        with open(file_path, 'w') as f:
            f.writelines(new_lines)
        
        print(f"已修改: {filename}")

print("所有emoji文件的头文件包含已更新！")
